﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Microsoft.Win32;
using Resn.WhuPub.BLL;
using System.Collections.ObjectModel;

namespace Resn.WhuPub.WPFClientUI
{
        /// <summary>
        /// ManageExamineePage.xaml 的交互逻辑
        /// </summary>
        public partial class ManageCategorysPage : Page
        {
                private readonly GlobalManager _gm = GlobalManager.Instance;

                public ManageCategorysPage()
                {
                        InitializeComponent();
                }

                private void Page_Loaded(object sender, RoutedEventArgs e)
                {
                        if (_gm.LoginEmployee == null)
                        {
                                MessageBox.Show("请先登录系统");
                                NavigationService.Navigate(new Uri("StartPage.xaml", UriKind.Relative));
                        }
                        LayoutRoot.DataContext = _gm;
                }

                private void CreateButton_Click(object sender, RoutedEventArgs e)
                {
                        NavigationService.Navigate(new Uri("CreateCategoryPage.xaml", UriKind.Relative));
                }

                private void UpdateButton_Click(object sender, RoutedEventArgs e)
                {
                        NavigationService.Navigate(new Uri("UpdateCategoryWindow.xaml", UriKind.Relative));
                }

                private void DeleteButton_Click(object sender, RoutedEventArgs e)
                {
                        // 在此处新建事件处理程序实现。
                        if (_gm.Category == null)
                        {
                                MessageBox.Show("请选择要删除的门类");
                                return;
                        }

                        if (
                                MessageBox.Show("确定要删除门类" + _gm.Category.Name + "及其所属科目吗？",
                                                "警告", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                        {
                                _gm.Category.Delete();
                                _gm.Category = null;

                                NavigationService.Navigate(new Uri("ManageCategorysPage.xaml", UriKind.Relative));
                        }
                }

                

                private void SearchButton_Click(object sender, RoutedEventArgs e)
                {
                        //new SearchCategoryWindow().ShowDialog();
                }

                private void CreateSubjectButton_Click(object sender, RoutedEventArgs e)
                {
                        //new CreateSubjectWindow().ShowDialog();
                }

                private void CategorysListBox_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
                {
                        if (_gm.Category == null)
                        {
                                MessageBox.Show("请选择要查看的门类");
                                return;
                        }

                        _gm.Subjects = new ObservableCollection<Subject>(_gm.Category.Subjects);
                        NavigationService.Navigate(new Uri("ManageSubjectsPage.xaml", UriKind.Relative));
                }

                
                
        }
}